import axios from 'axios'
import { ElMessage } from 'element-plus'

const http = axios.create({
  baseURL: import.meta.env.DEV
    ? 'http://192.168.159.1:8081/wallpaper-api'
    : 'http://192.168.159.1:8081/wallpaper-api',
  timeout: 10000
})

http.interceptors.request.use((config) => {
  return config
})

http.interceptors.response.use(
  (response) => {
    return response.data
  },
  (error) => {
    ElMessage.error('图片加载失败')
    return Promise.reject(error)
  }
)

export { http }
